package com.lineage.server.datatables;

import com.lineage.DatabaseFactory;
import com.lineage.server.templates.L1Taketreasure;
import com.lineage.server.utils.PerformanceTimer;
import com.lineage.server.utils.SQLUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class Taketreasure {
  private static final Log _log = LogFactory.getLog(Taketreasure.class);
  
  private static Taketreasure _instance;
  
  private static final ArrayList<L1Taketreasure> _stealList = new ArrayList<>();
  
  public static Taketreasure getInstance() {
    if (_instance == null)
      _instance = new Taketreasure(); 
    return _instance;
  }
  
  public final void load() {
    PerformanceTimer timer = new PerformanceTimer();
    Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {
      con = DatabaseFactory.get().getConnection();
      pstm = con.prepareStatement("SELECT * FROM w_敌人死亡夺宝");
      rs = pstm.executeQuery();
      while (rs.next()) {
        int item_id = rs.getInt("item_id");
        int level = rs.getInt("level");
        int mete_level = rs.getInt("mete_level");
        int steal_chance = rs.getInt("steal_chance");
        int min_steal_count = rs.getInt("min_steal_count");
        int max_steal_count = rs.getInt("max_steal_count");
        boolean is_broadcast = rs.getBoolean("is_broadcast");
        boolean drop_on_floor = rs.getBoolean("drop_on_floor");
        int anti_steal_item_id = rs.getInt("anti_steal_item_id");
        String dropmsg = rs.getString("dropmsg");
        L1Taketreasure itemSteal = new L1Taketreasure(item_id, level, mete_level, steal_chance, 
            min_steal_count, max_steal_count, is_broadcast, drop_on_floor, anti_steal_item_id, dropmsg);
        _stealList.add(itemSteal);
      } 
    } catch (SQLException e) {
      _log.error(e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    } 
  }
  
  public final ArrayList<L1Taketreasure> getList() {
    return _stealList;
  }
}
